let db = require('../db/index')

exports.all = (req, res) => {        //获取classlist表全部数据
    var sql = 'select * from classlist_yang'
    db.query(sql, (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}
exports.get = (req, res) => {        //通过id查询数据
    var sql = 'select * from classlist_yang where number = ?'    //？用于占位
    db.query(sql, [req.query.number], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}

exports.del = (req, res) => {        //通过id删除数据
    var sql = 'delete from classlist_yang where id = ?'
    db.query(sql, [req.query.id], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}

exports.add = (req, res) => {        //向classlist表添加数据
    var sql = 'insert into classlist_yang (id,name,class,password,number,club) values (?,?,?,?,?,?)'
    db.query(sql, [req.query.id, req.query.name, req.query.class, req.query.password, req.query.number, req.query.club], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}

exports.update = (req, res) => {        //通过id更新数据
    var sql = 'update classlist_yang set name = ?, class = ?, password = ?, number = ?, club = ? where id = ?'
    db.query(sql, [req.query.name, req.query.class,req.query.password, req.query.number, req.query.club, req.query.id,], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}

